<?php
@session_start();
    include_once '../../../Model/M_Ingrediente.php';
    $ingrediente = new M_Ingrediente();
    $listaIngredientes = $ingrediente->searchStockIngrediente_All();
    
?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link rel="stylesheet" href="../../css/style2.css" type="text/css">
        <script src="../../js/amcharts.js" type="text/javascript"></script> 
        <script type="text/javascript">
            function get_random_color() 
            {
                var color = "";
                for(var i = 0; i < 3; i++) {
                    var sub = Math.floor(Math.random() * 256).toString(16);
                    color += (sub.length == 1 ? "0" + sub : sub);
                }
                return "#" + color;
            }
        </script>
        <script type="text/javascript">
            var chart;

            var chartData = [
            <?
            for($i = 0; $i < count($listaIngredientes); $i++)
            {
                $nombre = $listaIngredientes[$i]['nombre'];
                $stock  = $listaIngredientes[$i]['stock'];                
                echo("{
                    country: '$nombre',
                    visits: $stock,
                    color: get_random_color()
                    },");
                ?>
                <?
            }
            ?>
            ];
            AmCharts.ready(function () {
                // SERIAL CHART
                chart = new AmCharts.AmSerialChart();
                chart.dataProvider = chartData;
                chart.categoryField = "country";
                // the following two lines makes chart 3D
                chart.depth3D = 20;
                chart.angle = 30;

                // AXES
                // category
                var categoryAxis = chart.categoryAxis;
                categoryAxis.labelRotation = 90;
                categoryAxis.dashLength = 5;
                categoryAxis.gridPosition = "start";

                // value
                var valueAxis = new AmCharts.ValueAxis();
                valueAxis.title = "Mes";
                valueAxis.dashLength = 5;
                chart.addValueAxis(valueAxis);

                // GRAPH            
                var graph = new AmCharts.AmGraph();
                graph.valueField = "visits";
                graph.colorField = "color";
                graph.balloonText = "[[category]]: [[value]]";
                graph.type = "column";
                graph.lineAlpha = 0;
                graph.fillAlphas = 1;
                chart.addGraph(graph);

                // WRITE
                chart.write("chartdiv");
            });
        </script>
    </head>
    
    <body>
        <div id="chartdiv" style="width: 100%; height: 400px;"></div>
    </body>

</html>
